#!/usr/bin/env node

require('dotenv').config()

const version = require('../package.json').version
const execute = require('child_process').execSync

const clientPort = process.env.ARAGON_PORT || process.env.REACT_APP_PORT || 3000

if (
  process.env.ARAGON_ETH_NETWORK_TYPE === 'main' &&
  !process.env.ARAGON_DEFAULT_ETH_NODE
) {
  console.log(
    '⚠️  You are connecting the Aragon client to mainnet but have not specified an Ethereum node.'
  )
  console.log(
    '    Connecting to the default node (wss://mainnet.eth.aragon.network/ws) in a local'
  )
  console.log(
    '    environment may result in severe slowdowns when trying to fetch Ethereum events or state.'
  )
  console.log()
  console.log(
    "➡️  During development, it is recommended to override the 'ARAGON_DEFAULT_ETH_NODE' environment"
  )
  console.log(
    '    variable with an Infura (infura.io) mainnet node to accelerate loading Ethereum events and state.'
  )
  console.log(
    '    You may do so by directly setting an environment variable or by using a .env file.'
  )
}

execute(`copy-aragon-ui-assets -n aragon-ui ./public`, {
  stdio: 'inherit',
})

process.env.ARAGON_PACKAGE_VERSION = version
execute(
  `parcel serve src/index.html --port ${clientPort} --out-dir ./public --no-cache`,
  { stdio: 'inherit' }
)
